package com.cq.cqut.meimessage.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.meimessage.R;

public class TitleActivity extends Activity implements OnClickListener{
	
	private TextView TitleTextView;
    private Button BackwardbButton;
    private Button ForwardButton;
    private FrameLayout ContentLayout;
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setupViews();
    }
	private void setupViews() {
		super.setContentView(R.layout.layout_title_activity);
		TitleTextView = (TextView) findViewById(R.id.text_title);
        ContentLayout = (FrameLayout) findViewById(R.id.layout_content);
        BackwardbButton = (Button) findViewById(R.id.button_backward);
        ForwardButton = (Button) findViewById(R.id.button_forward);
	}

	protected void showBackwardView(String backwardResid, boolean show) {
        if (BackwardbButton != null) {
            if (show) {
                BackwardbButton.setText(backwardResid);
                BackwardbButton.setVisibility(View.VISIBLE);
            } else {
                BackwardbButton.setVisibility(View.INVISIBLE);
            }
        } 
    }
	
	protected void showForwardView(String forwardResId, boolean show) {
        if (ForwardButton != null) {
            if (show) {
                ForwardButton.setVisibility(View.VISIBLE);
                ForwardButton.setText(forwardResId);
            } else {
                ForwardButton.setVisibility(View.INVISIBLE);
            }
        } 
    }
	
	@Override
	public void onClick(View v) {
		 switch (v.getId()) {
		 
         case R.id.button_backward:
             onBackward(v);
             break;
             
         case R.id.button_forward:
             onForward(v);
             break;
             
         default:
             break;
		 }
	}
	
	//BackwardButton
	protected void onBackward(View backwardView) {
        finish();
    }
	//ForwardButton
	protected void onForward(View forwardView) {
		
    }
	
	public void setTitle(int titleId) {
        TitleTextView.setText(titleId);
    }

    @Override
    public void setTitle(CharSequence title) {
        TitleTextView.setText(title);
    }


    @Override
    public void setTitleColor(int textColor) {
        TitleTextView.setTextColor(textColor);
    }


    @Override
    public void setContentView(int layoutResID) {
        ContentLayout.removeAllViews();
        View.inflate(this, layoutResID, ContentLayout);
        onContentChanged();
    }

    @Override
    public void setContentView(View view) {
        ContentLayout.removeAllViews();
        ContentLayout.addView(view);
        onContentChanged();
    }

    @Override
    public void setContentView(View view, LayoutParams params) {
        ContentLayout.removeAllViews();
        ContentLayout.addView(view, params);
        onContentChanged();
    }

}
